<template>
	<view class="body">
		<view>
			<form @submit="submit" @reset="formReset">
				<view style="padding: 3ex 3ex;">
					<view class="uni-form-item uni-column form_row" style="margin-top: 20%;">
						<p style="font-size: 20px;text-align: center;color: skyblue">科德配料速算</p>
					</view>
					
					<view class="uni-form-item uni-column form_row" style="margin-top: 20%;">
						<input name="loginName" class="form_row_input" require style="" placeholder="账号" />
					</view>
					
					<view class="uni-form-item uni-column form_row" style="margin-top: 10%;">
						<input name="password" password class="form_row_input" placeholder="密码" />
					</view>

					<text class="msg" :style="{color : color}">{{msg}}</text>
					<view class="uni-btn-v" style="margin-top: 30%;width: 70%;margin-left: 15%;">
						<button type="primary" form-type="submit">登录</button>
						
					</view>
					
					
					<view>
						<a style="color: lightgray;text-align: center;position: absolute;bottom: 3%;left: 35%;">
							 copyright@ KD
						</a>
					</view>

				</view>
			</form>
		</view>
	</view>
</template>

<script>
	import configService from '@/common/config.service.js';
	import cache from "@/common/cache.js";
	const apiUrl = configService.apiUrl;
	export default {
		data() {
			return {
				param: {},
				msg: '',
				color: 'red',
			}
		},
		methods: {
			submit(e) {
				uni.showLoading({
					title: '加载中...'
				});
				let _this = this;
				_this.param = e.detail.value; //表单数据
				uni.request({
					url: apiUrl + "/login/login",
					method: 'POST',
					data: _this.param,
					success: (res) => {
						console.log(res)
						if (res.data.code == 200) {
							_this.$common.showToast('成功');
							let token = res.data.data;
							const timestamp = new Date().getTime();
							console.log(timestamp);
							token['loginTime'] = timestamp;
							console.log(token);
							console.log("newtooken11111111111");
							uni.setStorageSync("user",token);
							uni.setStorageSync("deptId", token.deptId);
							uni.switchTab({ url: '/pages/index/index' })//bar页面
							// _this.$common.navigateTo('/pages/index/index?');
						} else {
							_this.color = 'red';
							_this.msg = res.data.msg;
							_this.$common.showToast(_this.msg);
						}
						uni.hideLoading();
					},
					fail: (err) => {
						_this.loading = false;
						console.log(err)
						_this.msg = err;
					},
				})

			}

		}
	}
</script>

<style scoped lang="scss">
	.msg {
		margin-left: 14%;
	}

	.page-wrap {
		height: 100%;
		padding-left: 30rpx;
		padding-right: 30rpx;

		.test-view {
			height: 300rpx;
		}

		.item_box {
			margin-top: 3%;
			background-color: white;
			border-radius: 3px;
		}

	}

	.form_row {
		flex-direction: row;
		justify-content: space-around;
	}

	// .form_row_lable {
	// 	float: left;
	// 	background-color: white;
	// 	border-radius: 1px;
	// 	text-align: left;
	// 	padding: 12upx 18upx;
	// 	width: 30%;
	// }

	.form_row_input {
		width: 70%;
		margin-left: 10%;
		border: 1upx solid #dadbde;
		padding: 12upx 18upx;
		border-radius: 8upx;
		font-size: 30upx;
		color: rgb(48, 49, 51);
	}

	.form_row_btn {
		flex-direction: row;
		justify-content: center;
	}
</style>